package com.hospital.phyexam.controller;

import com.alibaba.fastjson.JSONObject;
import com.hospital.phyexam.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: Hospital
 * @description: 体检学生controller
 * @author: 杨曼珍
 * @create: 2019-01-12 20:04
 **/
@Controller
@RequestMapping(value = "/phyStudent")
public class StudentController {
    @Autowired
    StudentService studentService;

    @RequestMapping(value = "/all", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    @ResponseBody
    public String getStu() {
        return studentService.getAllStu();
    }

    @RequestMapping(value = "/stuName", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    @ResponseBody
    public String getStuByName(@RequestBody String string) {
        String name=JSONObject.parseObject(string).getString("stuName");
        return studentService.selectByStuName(name);
    }

    @RequestMapping(value = "/batch", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    @ResponseBody
    public String getStuBybatch(@RequestBody String string) {
        String name=JSONObject.parseObject(string).getString("phyExmBatchName");
        return studentService.selectByBatchName(name);
    }
    @RequestMapping(value = "/add", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    @ResponseBody
    public String insertStu(@RequestBody String string) {
        Integer batchId=Integer.parseInt(JSONObject.parseObject(string).getString("batchId"));
        Integer deptId=Integer.parseInt(JSONObject.parseObject(string).getString("deptId"));
        return studentService.add(batchId,deptId);
    }
}
